package com.lsa.edmonds.chap1;
import com.lsa.helpers.Utils;

public class BinarySearch
{
	public int search(int[] array, int el)
	{
		if (Utils.isEmpty(array))
			return -1;
		
		int left = 0;
		int right = array.length -1;
		
		while(left <= right)
		{
			int middle = (left + right) >>> 1;
			if (array[middle] == el)
			{
				return middle;
			}
			else if (array[middle] < el)
			{
				left = middle + 1;
			}
			else
			{
				right = middle - 1;
			}
		}
		
		return -1;
	}
}
